<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客登录页</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
    <!-- 引入jquery的js文件 -->
    <script src="js/jquery.min.js"></script>
</head>
<body>
     <!-- 导航栏 -->
     <div class="nav">
        <img src="image/导航栏.jpg">
        <span>博客系统登录</span>
        <div class="spacer"></div>
        <!-- 这个标签只用于占位 -->
        <a href="#">主页</a>
        <a href="#">写博客</a>
        <a href="#">注销</a>
     </div>
     <!-- 贯穿整个浏览器页面 -->
     <div class="login-container">
     <!-- 做一个登录对话框 -->
     <div class="login-dialog">
        <h3>登录</h3>
        <div class="username">
            <span>用户名</span>
            <input type="text" name="" id="username" placeholder="手机号/邮箱">
        </div>
        <div class="password">
            <span>密码</span>
            <input type="password" id="password" >
        </div>
        <div class="submit1">
            <button id="submit" onclick="mysub()">登录</button>
        </div>
     </div>
    </div>
    <script>
        function mysub(){
            // 1.在提交后要进行非空判断
            // 先得到输入的组件
            var username = jQuery("#userrname");
            var password = jQuery("#password");
            if(username.val().trim()==""){
                alert("请先输入用户名");
                username.focus();
                return false;
            }
            if(password.val().trim()==""){
                alert("请先输入密码");
                password.focus();
                return false;
            }
            //2.发送登录请求给后端
            jQuery.ajax({
                url:"/user/login",
                type:"POST",
                data:{
                    "username":username.val().trim(),
                    "password":password.val().trim()
                },
                success:function(result){
                  if(result.code==200&&result.data==1){
                    alert("登录成功！");
                    location.href="blog_list.html";
                  }else{
                    alert("抱歉：登陆失败！");
                  }  
                }
            });

        }
    </script>
</body>
</html>